package com.example.fw;

import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.operators.JFrameOperator;

import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: pshevchenko
 * Date: 06.03.13
 * Time: 17:47
 * To change this template use File | Settings | File Templates.
 */
public class ApplicationManager {

    private Properties properties;

    private FolderHelper folderHelper;
    private MenuHelper menuHelper;

    private JFrameOperator mainFrame;

    public ApplicationManager(Properties properties) {
        this.properties = properties;
    }

    public void decompose() {
        getApplication().requestClose();
    }

    public FolderHelper getFolderHelper() {

        if (folderHelper == null){
            folderHelper = new FolderHelper(this);
        }
        return folderHelper;
    }

    public JFrameOperator getApplication() {
        if (mainFrame == null){

            try {
                new ClassReference("addressbook.AddressBookFrame").startApplication();
                mainFrame = new JFrameOperator("jAddressBook");
            } catch (Exception e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return mainFrame;

    }

    public MenuHelper getMenuHelper() {

        if (menuHelper == null){
            menuHelper = new MenuHelper(this);
        }
        return menuHelper;

    }
}
